//
//  DRGuideViewController.m
//  DoctorRen
//
//  Created by Macx on 2018/11/28.
//

#import "DRGuideViewController.h"
#import <Masonry/Masonry.h>

@interface DRGuideViewController ()

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, strong) NSArray *images;

@property (nonatomic, assign) NSInteger currentIndex;

@property (nonatomic, strong) UIButton *quitButton;

@end

@implementation DRGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 1; i < 13; i++) {
        NSString *imageName = [NSString stringWithFormat:@"guide_%d",i];
        [array addObject:imageName];
    }
    self.images = [array copy];
    self.currentIndex = 0;
    [self setUI];
    self.imageView.image = [UIImage imageNamed:self.images[self.currentIndex]];
}

-(void) setUI{
    self.view.backgroundColor = UIColorFromHex(0x878787);
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(20);
    }];
    
    [self.imageView addSubview:self.quitButton];
    [self.quitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
    self.quitButton.layer.cornerRadius = 15;
    [self.quitButton addTarget:self action:@selector(dismiss) forControlEvents:(UIControlEventTouchUpInside)];
}

-(void) dismiss{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void) tapImage{
    self.currentIndex += 1;
    if (self.currentIndex < self.images.count) {
        self.imageView.image = [UIImage imageNamed:self.images[self.currentIndex]];
    }else{
        //跳出
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}


-(UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [UIImageView new];
        _imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage)];
        [_imageView addGestureRecognizer:tap];
        [self.view addSubview:_imageView];
    }
    return _imageView;
}

-(UIButton *)quitButton{
    if (!_quitButton) {
        _quitButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_quitButton setTitle:@"退出" forState:(UIControlStateNormal)];
        [_quitButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _quitButton.backgroundColor = There_Green;
    }
    return _quitButton;
}


@end
